<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['ischecklogin']=cfc('core')->checklogin('','',true);
$return['isopenvoice']=$this->session('isopenvoice')?1:0;
if($_RQ['op']=='main'){
	$ismerch=$_RQ['ismerch'];
	if($ismerch){
		$jy_merch = $this->plugin_exists('jy_merch');
		if($jy_merch){
			$return['jy_merch']=1;
			$merchid=plugin('jy_merch')->checklogin();
			if($merchid){
				$id=$this->model('worker')->checkadd($merchid);
			}
			$worker = pdo_get('jy_aikefu_worker',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid));
		}
	}else{
		$worker = pdo_get('jy_aikefu_worker',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1));
	}
	if(empty($worker)){
		exi('您不是客服！','error','/index/');
	}
	$_SESSION['workerid']=$worker['id'];
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$cashdays=$this->setting['cash_day']?:1;
	$cashtime = mktime(0,0,0,date('m'),date('d')-$cashdays,date('Y'));
	$return['get_money']=pdo_getsum('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$worker['id'],'ispay'=>1),'price');
	$return['lastprice']=pdo_getsum('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$worker['id'],'ispay'=>1),'price');
	$return['yesprice']=pdo_getsum('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$worker['id'],'ispay'=>1,'createtime <'=>$cashtime),'price');
	$worker['today_money']=pdo_getsum('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$_SESSION['uid'],'ispay'=>1,'createtime >'=>$daytime),'price');
	$worker['today_num']=pdo_count('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$_SESSION['uid'],'ispay'=>1,'createtime >'=>$daytime));
	$worker['all_money']=pdo_getsum('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$_SESSION['uid'],'ispay'=>1),'price');
	$worker['all_num']=pdo_count('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$_SESSION['uid'],'ispay'=>1));
	$worker['viptime']=date('Y-m-d',$worker['viptime']);
	$worker['images']=json_decode($worker['images'],true);
	$worker['onlinetime']=json_decode($worker['onlinetime'],true);
	$worker['priceset']=json_decode($worker['priceset'],true);
	$worker['param']=json_decode($worker['param'],true);
	$worker['zixuns']=json_decode($worker['zixuns'],true);
	$worker['peixuns']=json_decode($worker['peixuns'],true);
	$worker['tags']=json_decode($worker['tags'],true);
	$worker['api_data']=json_decode($worker['api_data'],true);
	$worker['salenum']=pdo_count('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$worker['id']));
	if($_SESSION['wxapp_id']){
		$tmpid=cfc('wxapp_api')->get_tpl_template_id('17468',[1,2,3,7],'orderget','新服务任务通知','jy_aikefu');
		if($tmpid){
			$tmplIds[]=$tmpid;
		}
		$return['tmplIds']=$tmplIds;
	}
	$return['worker']=$worker;	
	set_html('title','客服中心');
	exi($return);
	
}
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$postdata=get_postdata();	
		$data=array(
				'logo'=>$postdata['logo'],
				'title'=>$postdata['title'],
				'isprice'=>$postdata['isprice'],
				'price'=>$postdata['price'],
				'mobileprice'=>$postdata['mobileprice'],
				'mobile'=>$postdata['mobile'],
		);
		$worker_id=pdo_getcolumn('jy_aikefu_worker',array('id'=>$_SESSION['workerid'],'uniacid'=>$_SESSION['uniacid']),'id');		
		if($worker_id){
			pdo_update('jy_aikefu_worker',$data,array('id'=>$worker_id));
			exi('修改成功','','main');		 
		}
	}
	$worker=pdo_get('jy_aikefu_worker',array('id'=>$_SESSION['workerid'],'uniacid'=>$_SESSION['uniacid']));
	$return['worker']=$worker;
	exi($return);
}
if($_RQ['op']=='setisonline'){
	$post=get_postdata();
	$id=$post['id'];
	$isonline=$post['isonline'];
	pdo_update('jy_aikefu_worker',array('isonline'=>$isonline),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	if($isonline==0){
		exi('成功离线！');	
	}elseif($isonline==1){
		exi('成功上线！');	
	}elseif($isonline==2){
		exi('成功忙碌！');	
	}	 
}
if($_RQ['op']=='getnew'){
	$worker = pdo_get('jy_aikefu_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['workerid'],'status'=>1));
	$params=array(
		'isread'=>0,
		'uniacid'=>$_SESSION['uniacid'],
		'workerid'=>$worker['id'],
	);
	$this->session('isopenvoice',1);
	$order=pdo_get('jy_aikefu_tcplog',$params);
	if($order['id']){
		exi($order);
	}else{
		exi('none');
	}
}
if($_RQ['op']=='setopenvoice'){
	$isopenvoice=$_RQ['isopenvoice'];
	$isopenvoice=$isopenvoice?1:0;
	$this->session('isopenvoice',$isopenvoice);
	pdo_update('jy_aikefu_worker',array('isonline'=>$isopenvoice),array('id'=>$_SESSION['workerid'],'uniacid'=>$_SESSION['uniacid']));
	exi($return);
}
?>